#include "UFOs.h"
#include "Box.h"
#include "RSManager.h"
#include "GameDefine.h"
#include "Sprite.h"
#include "ShareComponents.h"
#include "Camera.h"


UFOs::UFOs(Box* box) : Object(box, ObjAnti_DYNAMID), MoveObject()
{
	_sprite = RSManager::getInstance()->getSprite(UFO);
	_box->_size = _sprite->getRenderSize();		
	_isAlive = true;
	_hits = 1;
	delay = 0;
}


UFOs::~UFOs(void)
{
}

void UFOs::update1()
{
	if(_hits <= 0 || _box->_position.x > gl_camera->getRightSide())
		_isAlive = false;
	if (_box->_position.y - ground > 0)
	{
		if (_box->_position.x - right_side < 0)
			_box->_position.x += _box->_v.x;
		else
			_box->_position.y += _box->_v.y;
	}	
	else
		_box->_position.x -= _box->_v.x;
	delay += GAME_TIME;
	if (delay >= 80)
	{
		delay = 0;
		_sprite->Next();
	}		
}


void UFOs::update2()
{	
	if(_hits <= 0 || _box->_position.x < gl_camera->getLeftSide())
		_isAlive = false;	
	if (_box->_position.y - ground > 0)
	{
		if (_box->_position.x - left_side > 0)
			_box->_position.x += _box->_v.x;
		else
			_box->_position.y += _box->_v.y;
	}	
	else
		_box->_position.x -= _box->_v.x;
	delay += GAME_TIME;
	if (delay >= 80)
	{
		delay = 0;
		_sprite->Next();
	}	
}

void UFOs::render()
{	
	_sprite->Render(_box->_position);
}

Box* UFOs::getCollisionBox()
{
	_colBox->_position = _box->_position;
	_colBox->_size = _box->_size;
	_colBox->_v = _box->_v;
	return _colBox;
}

void UFOs::update()
{
	if(_box->_v.x > 0)
		update1();
	else
		update2();
}

